from rest_framework.views import APIView
from .enum_type import NumberPreifx
from .generate_code import Generate_code
from rest_framework.response import Response
from rest_framework import status

#生成各种函数的接口

class GenerateCode(APIView):

    def get(self,request,*args,**kwargs):
        '''

        生成各种编号的接口
        :param request:
        :param args:
        :param kwargs:
        :return:
        '''
        prefix=request.query_params.get('prefix',None)

        if prefix:
            if prefix in NumberPreifx.__members__:
                code=GenerateCode(NumberPreifx[prefix].value)
                return Response(data={'code':code},status=status.HTTP_200_OK)

            else:
                return Response(data={'detail':'prefix没有配置,参考enmu_type.py'},status=status.HTTP_404_NOT_FOUND)


        return  Response(data={'detail':'prefix没有,该参数是必传项'},status=status.HTTP_400_BAD_REQUEST)


